/**
* @description:	XOMS中回到顶部插件 已把该方法添加到xoms.base.js中,js不用单独引用该插件
* @author:	yanxiaoe
* @param {Object} {
* 	showHeight: 指定滚动100px时出现"回到顶部"按钮
* }
* @example  XOMS.scrollTop()
*/
define(['XOMS', 'jquery'], function(XOMS, $) {
	
	XOMS.scrollTop = function(settings) {
		var defaultSettings = {
//				width: 50,
//				height: 50,
//				right: 50,
//				bottom: 100,
//				cursor: 'pointer',
				// 出现回到顶部按钮的位置
				showHeight: 100
			};
		var _settings = $.extend({}, defaultSettings, settings);
		var element = $('<div class="xoms-scroll-top" title="回到顶部"><span class="glyphicon glyphicon-plane"></span></div>');
		// 把这一部分样式放到xoms.bootstrap.css中
		/*element.css({
			'width' : _settings.width + 'px',
			'height' : _settings.height + 'px',
			'line-height' : _settings.height + 'px',
			'font-size' : '25px',
			'text-align' : 'center',
			'position' : 'fixed',
			'bottom' : _settings.bottom + 'px',
			'right' : _settings.right + 'px',
			'display' : 'none',
			'cursor' : _settings.cursor,
			'border' : '1px solid #ddd',
			'background-color' : '#FCF8F8',
			'box-shadow' : '0 0 2px rgba(244, 244, 244, 0.6)',
			'color' : '#918F8F'
		});*/
		$('body').append(element);
		
		element.click(function(){
			var itl = -1;
			itl = setInterval(function(){
				var scrollHeight = $(window).scrollTop();
				var spacing = Math.ceil(scrollHeight*0.2);
				if((scrollHeight-spacing)<10) {
					$(window).scrollTop(0);
					clearInterval(itl);
				} else {
					$(window).scrollTop(scrollHeight-spacing);
				}
			}, 10);
		});
		
		$(window).scroll(function() {
			var scrollHeight = $(window).scrollTop();
			if(scrollHeight > _settings.showHeight) {
				element.show();
			} else {
				element.hide();
			}
		});
	};
	return XOMS.scrollTop;
});